package com.init.bootframe.business.controller;

import com.init.bootframe.business.service.ICustomerService;
import com.init.bootframe.business.vo.CustomerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private ICustomerService customerService; //客户service

    @PostMapping("/findCustomerList")
    public Map<String, Object> findCustomerList(@RequestBody CustomerVO customerVO) throws Exception {
        Map<String, Object> result = customerService.findCustomerList(customerVO);
        return result;
    }

    @PostMapping("/webs/findCustomerList")
    public List<CustomerVO> findCustomerLists(@RequestBody CustomerVO customerVO) throws Exception {
        List<CustomerVO> result = customerService.findCustomerLists(customerVO);
        return result;
    }

    /**
     * 查询客户详情
     * @param customerVO
     * @return
     * @throws Exception
     */
    @PostMapping("/findCustomer")
    public CustomerVO findCustomer(@RequestBody CustomerVO customerVO) throws Exception {
        CustomerVO result = customerService.findCustomer(customerVO);
        return result;
    }

    /**
     * 添加客户
     * @param customerVO
     * @return
     * @throws Exception
     */
    @PostMapping("/addCustomer")
    public Map<String, Object> addCustomer(@RequestBody CustomerVO customerVO) throws Exception {
        Map<String, Object> result = customerService.addCustomer(customerVO);
        return result;
    }

    /**
     * 更新客户
     * @param customerVO
     * @return
     * @throws Exception
     */
    @PostMapping("/updateCustomer")
    public Map<String, Object> updateCustomer(@RequestBody CustomerVO customerVO) throws Exception {
        Map<String, Object> result = customerService.updateCustomer(customerVO);
        return result;
    }

    /**
     * 删除客户
     * @param customerVO
     * @return
     * @throws Exception
     */
    @PostMapping("/deleteCustomer")
    public Map<String, Object> deleteCustomer(@RequestBody CustomerVO customerVO) throws Exception {
        Map<String, Object> result = customerService.deleteCustomer(customerVO);
        return result;
    }


}
